package com.love.marriage.common.enums;

import lombok.Getter;

import java.time.LocalDate;

@Getter
public enum MembershipType {

    MONTH("month", "月会员") {
        @Override
        public LocalDate calculateStartTime(LocalDate startDate) {
            if (startDate == null) {
                startDate = LocalDate.now();
            }
            return startDate.plusMonths(1);
        }
    },
    QUARTER("quarter", "季度会员") {
        @Override
        public LocalDate calculateStartTime(LocalDate startDate) {
            if (startDate == null) {
                startDate = LocalDate.now();
            }
            return startDate.plusMonths(3); // 季度为3个月
        }
    },
    YEAR("year", "年会员") {
        @Override
        public LocalDate calculateStartTime(LocalDate startDate) {
            if (startDate == null) {
                startDate = LocalDate.now();
            }
            return startDate.plusYears(1);
        }
    },
    FOUR_YEAR("four_year", "至尊会员") {
        @Override
        public LocalDate calculateStartTime(LocalDate startDate) {
            if (startDate == null) {
                startDate = LocalDate.now();
            }
            return startDate.plusYears(2);
        }
    }
    ;

    private final String code;
    private final String value;

    private MembershipType(String code, String value) {
        this.code = code;
        this.value = value;
    }

    // 抽象方法，每个枚举项实现自己计算时间的逻辑
    public abstract LocalDate calculateStartTime(LocalDate startDate);

    public static MembershipType getMembershipTypeByCode(String code) {
        for (MembershipType membershipType : MembershipType.values()) {
            if (membershipType.getCode().equals(code)) {
                return membershipType;
            }
        }
        return null;
    }
}

